package com.zhipu.resetbalance.utils.weight;

import android.text.TextUtils;

import java.nio.charset.StandardCharsets;

public class WeightStringUtils {
    /**
     *
     */
    private static StringBuilder weightSplice = new StringBuilder();






    /**
     * 重量处理
     * @param event
     * @return
     */
    public static String weightHandle(byte[] event){
        /**
         * 清空重量
         */
        weightSplice.setLength(0);
        /**
         * 正负
         */
        byte[] PlusOrMinus = {event[2]};
        String plusMinus = new String(PlusOrMinus, StandardCharsets.UTF_8);
        if(plusMinus.equals("+")){
            plusMinus = "";
        }
        /**
         * 前重量
         */
        byte[] FrontWeight = {event[3],event[4],event[5],event[6]};
        String frontWeight = new String(FrontWeight, StandardCharsets.UTF_8).replaceAll(" ","");
        if(TextUtils.isEmpty(frontWeight)){
            frontWeight = frontWeight.replaceAll("","0");
        }
//        System.out.println("前重量:" + frontWeight);
        /**
         * 后重量
         */
        byte[] RearWeight = {event[7],event[8]};
        String rearWeight = new String(RearWeight, StandardCharsets.UTF_8).replaceAll(" ","0");
//        System.out.println("后重量:" + rearWeight);
        /**
         * 使用StringBuilder拼接重量
         */
        weightSplice.append(plusMinus).append(frontWeight).append(".").append(rearWeight);
//        System.out.println("重量:" + weightSplice.toString());
        /**
         * 返回
         */
        return weightSplice.toString();
    }

}
